//
//  RTMainViewController.m
//  WeiLiToy_Example
//
//  Created by baxiang on 2018/1/18.
//  Copyright © 2018年 baxiang. All rights reserved.
//

#import "RTMainViewController.h"
#import "RBSideMenuController.h"
#import "RTCategoryController.h"
#import "RTDeviceInfoController.h"
#import "RBDeviceSettingController.h"
#import "RTUerSettingController.h"
@interface RTMainViewController ()

@end

@implementation RTMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"ROOBO机器人";
    self.navigationController.navigationBar.barTintColor = RTColorForBackground;
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_sidebar"] style:UIBarButtonItemStylePlain target:self action:@selector(showMenu)];
    barButtonItem.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = barButtonItem;
   
    self.automaticallyCalculatesItemWidths = YES;
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
   // self.redView.frame = CGRectMake(0, CGRectGetMaxY(self.menuView.frame), self.view.frame.size.width, 2.0);
}

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return 4;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    switch (index) {
        case 0: return @"资源分类";
        case 1: return @"设备信息";
        case 2: return @"设备设置";
        case 3: return @"用户设置";
    }
    return @"";
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    switch (index ) {
        case 0: return [[RTCategoryController alloc] init];
        case 1: return [[RTDeviceInfoController alloc] init];
        case 2: return [[RBDeviceSettingController alloc] init];
        case 3: return [[RTUerSettingController alloc] init];
    }
    return [[UIViewController alloc] init];
}

- (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index {
    CGFloat width = [super menuView:menu widthForItemAtIndex:index];
    return width + 20;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
   
    CGFloat leftMargin = self.showOnNavigationBar ? 50 : 0;
    CGFloat originY = self.showOnNavigationBar ? 0 : CGRectGetMaxY(self.navigationController.navigationBar.frame);
    return CGRectMake(leftMargin, originY, self.view.frame.size.width - 2*leftMargin, 44);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
  
    CGFloat originY = CGRectGetMaxY([self pageController:pageController preferredFrameForMenuView:self.menuView]);
    
    return CGRectMake(0, originY, self.view.frame.size.width, self.view.frame.size.height - originY);
}

-(void)showMenu{
    [self presentLeftMenuViewController];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
